home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / lst.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-19  |  3.9 KB  |  115 lines

  1. /*-
  2.  * lst.h --
  3.  *    Header for using the list library
  4.  *
  5.  * Copyright (c) 1988 by University of California Regents
  6.  *
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appears in all copies.  Neither the University of California nor
  11.  * Adam de Boor makes any representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Id: lst.h,v 1.10 88/11/17 20:51:41 adam Exp $ SPRITE (Berkeley)
  16.  */
  17. #ifndef _LST_H_
  18. #define _LST_H_
  19.  
  20. #include    <sprite.h>
  21.  
  22. /*
  23.  * basic typedef. This is what the Lst_ functions handle
  24.  */
  25.  
  26. typedef    struct    Lst    *Lst;
  27. typedef    struct    LstNode    *LstNode;
  28.  
  29. #define    NILLST        ((Lst) NIL)
  30. #define    NILLNODE    ((LstNode) NIL)
  31.  
  32. /*
  33.  * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
  34.  *    not to be freed.
  35.  * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
  36.  */
  37. #define NOFREE        ((void (*)()) 0)
  38. #define NOCOPY        ((ClientData (*)()) 0)
  39.  
  40. #define LST_CONCNEW    0   /* create new LstNode's when using Lst_Concat */
  41. #define LST_CONCLINK    1   /* relink LstNode's when using Lst_Concat */
  42.  
  43. /*
  44.  * Creation/destruction functions
  45.  */
  46. Lst          Lst_Init();            /* Create a new list */
  47. Lst              Lst_Duplicate();      /* Duplicate an existing list */
  48. void          Lst_Destroy();    /* Destroy an old one */
  49.  
  50. int              Lst_Length();            /* Find the length of a list */
  51. Boolean          Lst_IsEmpty();    /* True if list is empty */
  52.  
  53. /*
  54.  * Functions to modify a list
  55.  */
  56. ReturnStatus      Lst_Insert();            /* Insert an element before another */
  57. ReturnStatus      Lst_Append();            /* Insert an element after another */
  58. ReturnStatus      Lst_AtFront();        /* Place an element at the front of
  59.                      * a lst. */
  60. ReturnStatus      Lst_AtEnd();            /* Place an element at the end of a
  61.                      * lst. */
  62. ReturnStatus      Lst_Remove();            /* Remove an element */
  63. ReturnStatus      Lst_Replace();    /* Replace a node with a new value */
  64. ReturnStatus      Lst_Move();            /* Move an element to another place */
  65. ReturnStatus      Lst_Concat();            /* Concatenate two lists */
  66.  
  67. /*
  68.  * Node-specific functions
  69.  */
  70. LstNode          Lst_First();            /* Return first element in list */
  71. LstNode          Lst_Last();            /* Return last element in list */
  72. LstNode          Lst_Succ();            /* Return successor to given element */
  73. LstNode          Lst_Pred();            /* Return predecessor to given
  74.                      * element */
  75. ClientData      Lst_Datum();            /* Get datum from LstNode */
  76.  
  77. /*
  78.  * Functions for entire lists
  79.  */
  80. LstNode          Lst_Find();            /* Find an element in a list */
  81. LstNode          Lst_FindFrom();    /* Find an element starting from
  82.                      * somewhere */
  83. LstNode              Lst_Member();            /* See if the given datum is on the
  84.                      * list. Returns the LstNode containing
  85.                      * the datum */
  86. int              Lst_Index();            /* Returns the index of a datum in the
  87.                      * list, starting from 0 */
  88. void          Lst_ForEach();    /* Apply a function to all elements of
  89.                      * a lst */
  90. void              Lst_ForEachFrom();      /* Apply a function to all elements of
  91.                      * a lst starting from a certain point.
  92.                      * If the list is circular, the
  93.                      * application will wrap around to the
  94.                      * beginning of the list again. */
  95. /*
  96.  * these functions are for dealing with a list as a table, of sorts.
  97.  * An idea of the "current element" is kept and used by all the functions
  98.  * between Lst_Open() and Lst_Close().
  99.  */
  100. ReturnStatus      Lst_Open();            /* Open the list */
  101. LstNode          Lst_Prev();            /* Previous element */
  102. LstNode          Lst_Cur();            /* The current element, please */
  103. LstNode          Lst_Next();            /* Next element please */
  104. Boolean          Lst_IsAtEnd();    /* Done yet? */
  105. void          Lst_Close();            /* Finish table access */
  106.  
  107. /*
  108.  * for using the list as a queue
  109.  */
  110. ReturnStatus      Lst_EnQueue();    /* Place an element at tail of queue */
  111. ClientData      Lst_DeQueue();    /* Remove an element from head of
  112.                      * queue */
  113.  
  114. #endif _LST_H_
  115.